package com.tron.nettychat;

import com.tron.nettychat.nettysocket.TronServerBootstrap;
import io.netty.channel.ChannelFuture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class NettyChatApplication implements ApplicationRunner {

    private TronServerBootstrap serverBootstrap;

    @Value("${netty.port}")
    private int port;

    @Value("${netty.url}")
    private String url;

    NettyChatApplication(@Autowired TronServerBootstrap tronServerBootstrap) {
        this.serverBootstrap = tronServerBootstrap;
    }

    public static void main(String[] args) {
        SpringApplication.run(NettyChatApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        ChannelFuture future = serverBootstrap.start(url, port);
    }
}
